#include "Chess.h"
#include <sys/mman.h>

bool chessboard::end = true;
int chessboard::player = -1;

int main() {

	int touch_fd = -1;
	int pos_x = -1, pos_y = -1, option = -1;

	//记录找到的指定文件数量
	int i, bmp_num = 0;

	//定义设备文件相关变量
	int lcd_fd = -1;
	int* lcd_fp = NULL;

	//打开屏幕
	lcd_fd = open("/dev/fb0", O_RDWR);
	if (lcd_fd == -1)
	{
		perror("open LCD failed");
		return -1;
	}

	//建立内存映射
	lcd_fp = (int*)mmap(NULL, 800 * 480 * 4, PROT_WRITE, MAP_SHARED, lcd_fd, 0);
	if (lcd_fp == NULL)
	{
		perror("mmap failed\n");
		return -1;
	}

	//打开触摸屏设备文件
	touch_fd = open("/dev/input/event0", O_RDONLY);
	if (touch_fd == -1)
	{
		perror("open /dev/input/event0 failed");
		return -1;
	}
	cout << "先行后列" << endl;

	tupian();

	while (1)
	{
		get_end_touch(touch_fd, &pos_x, &pos_y);
		cout  <<"pos_x: "<< pos_x << endl;
		cout << "pos_y: " << pos_y << endl;
	}
	chessboard C;
	C.play();
}
